package com.example.administrator.asdasd;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Created by Administrator on 2016/3/30.
 */
public class Publish_hz extends AppCompatActivity {

    private Button p_btn1;
    private Button p_btn2;
    private EditText p_et1;
    private EditText p_et2;
    private EditText p_et3;
    private EditText p_et4;
    private EditText p_et5;
    private EditText p_et6;
    private EditText p_et7;


    private TextView cd_tt1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.publish_hz);

        cd_tt1 = (TextView) findViewById(R.id.top1_text);
        cd_tt1.setText("发布货源");

        p_btn1 = (Button) findViewById(R.id.button1);
        p_btn2 = (Button) findViewById(R.id.button2);
        p_et1 = (EditText) findViewById(R.id.name);
        p_et2 = (EditText) findViewById(R.id.num);
        p_et3 = (EditText) findViewById(R.id.max);
        p_et4 = (EditText) findViewById(R.id.weizhi);
        p_et5 = (EditText) findViewById(R.id.time);
        p_et6 = (EditText) findViewById(R.id.aim);
        p_et7 = (EditText) findViewById(R.id.money);

        p_btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SQLdm s=new SQLdm();
                SQLiteDatabase db=s.openDatabase(getApplicationContext());

                ContentValues val =new ContentValues();

                val.put("name", p_et1.getText().toString());
                val.put("num", p_et2.getText().toString());
                val.put("max",p_et3.getText().toString());
                val.put("weizhi",p_et4.getText().toString());
                val.put("time",p_et5.getText().toString());
                val.put("aim",p_et6.getText().toString());
                val.put("money", p_et7.getText().toString());
                val.put("hzs","2");

                db.insert("hztb", null, val);
                db.close();
                Toast.makeText(getApplicationContext(),"发布成功",Toast.LENGTH_SHORT).show();
                finish();
            }
        });
        p_btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(),"取消发布",Toast.LENGTH_SHORT).show();
                finish();
            }
        });
    }
}
